defmodule AutoTimer do
    @moduledoc false
    require Logger

    @type second :: integer

    @spec start_timer(atom, atom, list, second) :: :ok | reference
    def start_timer(m, f, a, time) do
        try do
            apply(m, f, a)
            :timer.apply_after(time * 1000, __MODULE__, :auto_do, [m, f, a, time])
        rescue
            err ->
                Logger.error(inspect(err))
                :timer.apply_after(60000, __MODULE__, :auto_do, [m, f, a, time])
                :ok
        catch
            err ->
                Logger.error(inspect(err))
                :timer.apply_after(60000, __MODULE__, :auto_do, [m, f, a, time])
                :ok
        end
    end

end
